import fs from'fs'
import path from'path'

export default function createVersionFilePlugin(version) {
  return {
    name: 'generate-version-plugin',
    generateBundle(outputOptions) {
      const buildTime = new Date().toLocaleString();
      const versionContent = `Version: ${version}\nBuild Time: ${buildTime}\n`;
      const outputPath = path.join(outputOptions.dir || 'dist', 'version.txt');
      fs.writeFileSync(outputPath, versionContent, 'utf8');
    }
  };
}
